﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/lib/_LayoutPageLib.cshtml";
}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text"  name="LoginName" class="layui-input" id="username">
                </div>
            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    手机号码
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="ProtectMTel"  class="layui-input" id="userphone" >
                </div>
            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    电子邮箱
                </label>
                <div class="layui-input-inline">
                    <input type="text"  name="ProtectEMail" lay-verify="email"  class="layui-input" id="useremail">
                </div>                
            </div>
            <div class="layui-form-item" style="width:300px">
                <label class="layui-form-label">所属身份</label>
                <div class="layui-input-block" >
                    <select name="RoleId" lay-filter="aihao" id="userroles">
                        <option value="">--请选择--</option>
                        @foreach (var item in ViewBag.RolesName)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                       
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    登陆密码
                </label>
                <div class="layui-input-inline">
                    <input type="password"  name="Password" class="layui-input" id="password"/>                    
                </div>
            </div>            
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button class="layui-btn layui-btn-warm layui-btn-radius" lay-filter="add" lay-submit="" style="width:188px">添加</button>
            </div>
        </form>
    </div>
</div>
<script>
layui.use(['form', 'layer','jquery'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;
                //监听提交
                form.on('submit(add)',
                function (data) {
                    var phone = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
                    //手机号正则表达式
                    
                    if ($("#username").val()== "") {
                        layer.msg("请填写登录名", { icon: 5, anim: 6 });
                        return false;
                    }
                    if ($("#userphone").val() == "") {
                        layer.msg("请填写手机号码", { icon: 5 ,anim: 6})
                        return false;
                    }
                    if(!phone.test($("#userphone").val())){
                        layer.msg("请填写合法的手机号码", { icon: 5, anim: 6 })
                        return false;
                    }
                    if ($("#useremail").val() == "") {
                        layer.msg("请填写电子邮箱", { icon: 5, anim: 6 })
                        return false;
                    }
                    if ($("#userroles").val() == "") {
                        layer.msg("请选择身份信息", { icon: 5, anim: 6 })
                        return false;
                    }
                    if ($("#password").val() == "") {
                        layer.msg("请填写密码", { icon: 5, anim: 6 })
                        return false;
                    }
                    console.log(data);
                    //发异步，把数据提交给php
                    $.post("/AddAdmin/Add", data.field , function (res) {
                        if (res.success) {
                            layer.msg(res.msg, { icon: 6, time: 1500 }, function () {
                                window.location.reload();
                            })
                        } else {
                            layer.msg(res.msg, { icon: 5, anim: 6 })
                        }
                    })                    
                    return false;
                });
              });
</script>



